<?php

/**
 * Description of SearchPresenter
 *
 * @author Pavel Homolka
 */
class SearchPresenter extends BasePresenter {

    /**
     *
     * @var Reranking
     */
    private $reranking;

    /**
     *
     * @var Flickr
     */
    protected $flickr;

    public function startup() {
        parent::startup();

        $this->flickr = $this->context->flickr;
        $this->reranking = $this->context->reranking;
    }

    public function createComponentSearchForm() {
        $form = new SearchForm();
        $form->onSuccess[] = callback($this, 'seachFormSubmitted');
        return $form;
    }

    /**
     * Obsluha SearchForm komponenty.
     * 
     * @param type $form 
     */
    public function seachFormSubmitted($form) {
        $vales = $form->getValues();
        if (empty($vales['gps'])) {
            $this->flickr->search($vales['keyword'], $vales['numberResult']);
        } else {
            $coordinates = explode(';', $vales['gps']);
            $this->flickr->search($vales['keyword'], $vales['numberResult'], $coordinates[0], $coordinates[1], $vales['radius']);
        }
        $this->redirect('Reranking:showResult');
    }

}